<pre>

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import bingosoft.components.base.helper.LogHelper;
import bingosoft.components.base.service.PageQueryRequest;
import bingosoft.components.base.service.Result;
import bingosoft.components.base.service.ResultEntity;
import bingosoft.components.base.service.ResultPage;
import leap.core.junit.AppTestBase;
import leap.lang.Assert;

/**
 * @author ${author}
 * @功能描述 ${table.tableComment}业务服务测试类
 * @创建时间 ${date}
 */
public class ${table.capitalTableName}ServiceTest extends AppTestBase {

	/**
	 *  ${table.tableComment}业务服务接口实现类
	 */
	private ${table.capitalTableName}Service ${table.humpTableName}Service = new ${table.capitalTableName}Service();
	
	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	/**
	 * 测试查询${table.tableComment} - success
	 */
	@Test
	public void testQuery${table.capitalTableName}s() {
		
		PageQueryRequest pageQueryRequest = new PageQueryRequest();
		Map&lt;String, Object&gt; params = new HashMap&lt;String,Object&gt;();
		ResultEntity&lt;List&lt;${table.capitalTableName}Form&gt;&gt; result = this.${table.humpTableName}Service.query${table.capitalTableName}s(pageQueryRequest, params);
		
		Assert.isTrue(result.isSuccess());
		LogHelper.println("result", result);
	}

	/**
	 * 测试分页查询${table.tableComment} - success
	 */
	@Test
	public void testPageQuery${table.capitalTableName}s() {
		PageQueryRequest pageQueryRequest = new PageQueryRequest();
		Map&lt;String, Object&gt; params = new HashMap&lt;String,Object&gt;();
		ResultEntity&lt;ResultPage&lt;List&lt;${table.capitalTableName}Form&gt;&gt;&gt; result = this.${table.humpTableName}Service.pageQuery${table.capitalTableName}s(pageQueryRequest, params);
		
		Assert.isTrue(result.isSuccess());
		LogHelper.println("result", result);
	}

	/**
	 * 测试创建${table.tableComment} - fail 参数为null
	 */
	@Test
	public void testCreate${table.capitalTableName}_fail_null() {
		Result result = this.${table.humpTableName}Service.create${table.capitalTableName}(null);
		Assert.isFalse(result.isSuccess());
		assertEquals(${table.capitalTableName}Service.MESSAGE_PARAM_OBJ_NULL, result.getMessage());
		LogHelper.println("result", result);
	}
	
	/**
	 * 测试创建${table.tableComment} - success
	 */
	@Test
	public void testCreate${table.capitalTableName}() {
		${table.capitalTableName}Form ${table.humpTableName}Form = build${table.capitalTableName}Form(1);
		Result result = this.${table.humpTableName}Service.create${table.capitalTableName}(${table.humpTableName}Form);
		Assert.isTrue(result.isSuccess());
		LogHelper.println("result", result);
	}

	/**
	 * 测试修改${table.tableComment} - fail 参数为null
	 */
	@Test
	public void testUpdate${table.capitalTableName}_fail_null() {
		Result result = this.${table.humpTableName}Service.update${table.capitalTableName}(null);
		Assert.isFalse(result.isSuccess());
		assertEquals(${table.capitalTableName}Service.MESSAGE_PARAM_OBJ_NULL, result.getMessage());
		LogHelper.println("result", result);
	}
	
	/**
	 * 测试修改${table.tableComment} - fail ID不存在
	 */
	@Test
	public void testUpdate${table.capitalTableName}_fail_noExist() {
		${table.capitalTableName}Form ${table.humpTableName}Form = build${table.capitalTableName}Form(1);
		${table.humpTableName}Form.set${pkCol.capitalColumnName}("null");
		Result result = this.${table.humpTableName}Service.update${table.capitalTableName}(${table.humpTableName}Form);
		Assert.isFalse(result.isSuccess());
		assertEquals(${table.capitalTableName}Service.MESSAGE_GET_FAIL, result.getMessage());
		LogHelper.println("result", result);
	}
	
	/**
	 * 测试修改${table.tableComment} - success
	 */
	@Test
	public void testUpdate${table.capitalTableName}() {
		${table.capitalTableName}Form ${table.humpTableName}Form = build${table.capitalTableName}Form(1);
		Result result = this.${table.humpTableName}Service.create${table.capitalTableName}(${table.humpTableName}Form);
		Assert.isTrue(result.isSuccess());

		result = this.${table.humpTableName}Service.update${table.capitalTableName}(${table.humpTableName}Form);
		Assert.isTrue(result.isSuccess());
		LogHelper.println("result", result);
	}

	/**
	 * 测试获取${table.tableComment} - fail 参数为null
	 */
	@Test
	public void testGet${table.capitalTableName}_fail_null() {
		ResultEntity&lt;${table.capitalTableName}Form&gt; resultEntity = this.${table.humpTableName}Service.get${table.capitalTableName}(null);
		Assert.isFalse(resultEntity.isSuccess());
		assertEquals(${table.capitalTableName}Service.MESSAGE_PARAM_ID_NULL, resultEntity.getMessage());
		LogHelper.println("resultEntity", resultEntity);
	}
	
	/**
	 * 测试获取${table.tableComment} - fail ID不存在
	 */
	@Test
	public void testGet${table.capitalTableName}_fail_noExist() {
		ResultEntity&lt;${table.capitalTableName}Form&gt; resultEntity = this.${table.humpTableName}Service.get${table.capitalTableName}("null");
		Assert.isFalse(resultEntity.isSuccess());
		assertEquals(${table.capitalTableName}Service.MESSAGE_GET_FAIL, resultEntity.getMessage());
		LogHelper.println("resultEntity", resultEntity);
	}
	
	/**
	 * 测试获取${table.tableComment} - success
	 */
	@Test
	public void testGet${table.capitalTableName}() {
		String ${pkCol.columnName} = getExist${pkCol.capitalColumnName}();
		ResultEntity&lt;${table.capitalTableName}Form&gt; resultEntity = this.${table.humpTableName}Service.get${table.capitalTableName}(${pkCol.columnName});
		Assert.isTrue(resultEntity.isSuccess());
		LogHelper.println("resultEntity", resultEntity);
	}

	/**
	 * 测试获取${table.tableComment} - fail 参数为null
	 */
	@Test
	public void testGet${table.capitalTableName}Model_fail_null() {
		ResultEntity&lt;${table.capitalTableName}Model&gt; resultEntity = this.${table.humpTableName}Service.get${table.capitalTableName}Model(null);
		Assert.isFalse(resultEntity.isSuccess());
		assertEquals(${table.capitalTableName}Service.MESSAGE_PARAM_ID_NULL, resultEntity.getMessage());
		LogHelper.println("resultEntity", resultEntity);
	}
	
	/**
	 * 测试获取${table.tableComment} - fail ID不存在
	 */
	@Test
	public void testGet${table.capitalTableName}Model_fail_noExist() {
		ResultEntity&lt;${table.capitalTableName}Model&gt; resultEntity = this.${table.humpTableName}Service.get${table.capitalTableName}Model("null");
		Assert.isFalse(resultEntity.isSuccess());
		assertEquals(${table.capitalTableName}Service.MESSAGE_GET_FAIL, resultEntity.getMessage());
		LogHelper.println("resultEntity", resultEntity);
	}
	
	/**
	 * 测试获取${table.tableComment} - success
	 */
	@Test
	public void testGet${table.capitalTableName}Model() {
		String ${pkCol.columnName} = getExist${pkCol.capitalColumnName}();
		ResultEntity&lt;${table.capitalTableName}Model&gt; resultEntity = this.${table.humpTableName}Service.get${table.capitalTableName}Model(${pkCol.columnName});
		Assert.isTrue(resultEntity.isSuccess());
		LogHelper.println("resultEntity", resultEntity);
	}
	
	/**
	 * 测试删除${table.tableComment} - fail 参数为null
	 */
	@Test
	public void testDelete${table.capitalTableName}_fail_null() {
		Result result = this.${table.humpTableName}Service.delete${table.capitalTableName}(null);
		Assert.isFalse(result.isSuccess());
		assertEquals(${table.capitalTableName}Service.MESSAGE_PARAM_ID_NULL, result.getMessage());
		LogHelper.println("result", result);
	}
	
	/**
	 * 测试删除${table.tableComment} - fail ID不存在
	 */
	@Test
	public void testDelete${table.capitalTableName}_fail_noExist() {
		Result result = this.${table.humpTableName}Service.delete${table.capitalTableName}("null");
		Assert.isFalse(result.isSuccess());
		assertEquals(${table.capitalTableName}Service.MESSAGE_DELETE_FAIL, result.getMessage());
		LogHelper.println("result", result);
	}
	
	/**
	 * 测试删除${table.tableComment} - success
	 */
	@Test
	public void testDelete${table.capitalTableName}() {
		String ${pkCol.columnName} = getExist${pkCol.capitalColumnName}();
		Result result = this.${table.humpTableName}Service.delete${table.capitalTableName}(${pkCol.columnName});
		Assert.isTrue(result.isSuccess());
		LogHelper.println("result", result);
	}

	/**
	 * 构建${table.tableComment}
	 * @param i
	 * @return
	 */
	public static ${table.capitalTableName}Form build${table.capitalTableName}Form(int i) {
		${table.capitalTableName}Form ${table.humpTableName}Form = new ${table.capitalTableName}Form();
<!-- #for(col : columns) -->
		${table.humpTableName}Form.set${col.capitalColumnName}("${col.capitalColumnName}" + i);
<!-- #endfor -->
		return ${table.humpTableName}Form;
	}
	
	/**
	 * 获取存在的${table.tableComment}ID
	 * @return
	 */
	public static String getExist${pkCol.capitalColumnName}() {
		${table.capitalTableName}Form ${table.humpTableName}Form = build${table.capitalTableName}Form(1);
		Result result = new ${table.capitalTableName}Service().create${table.capitalTableName}(${table.humpTableName}Form);
		Assert.isTrue(result.isSuccess());

		return ${table.humpTableName}Form.get${pkCol.capitalColumnName}();
	}
}
</pre>
